﻿using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using log4net;

namespace CustomerAssistant
{
    public static class LogHelper
    {
        private static readonly ILog ErrorLogger = LogManager.GetLogger("ErrorLogger");

        static LogHelper()
        {
            log4net.Config.XmlConfigurator.Configure(new FileInfo("log4net.config"));
        }
        public static void LogInfo(string msg)
        {
            ErrorLogger.Info(msg);
        }
        public static void LogError(string msg, bool notifyUser = false)
        {
            if (notifyUser)
                NotifyUser(msg, Properties.Resource.error, ImageFormat.Png);
            ErrorLogger.Error(msg);
        }

        public static void LogError(string msg, Exception exception, bool notifyUser = false)
        {
            if (notifyUser)
                NotifyUser(msg, Properties.Resource.error, ImageFormat.Png);
            ErrorLogger.Error(msg, exception);
        }

        public static void NotifyUser(string msg, Image image, ImageFormat fmt)
        {
            var msgWnd = (MessageWindow)SysHelper.UnityContainer.Resolve(typeof(MessageWindow), null);
            msgWnd.ShowMessage(msg, SysHelper.GetImageSource(image, fmt));
        }
    }
}